﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using DrivingCRM.Controller;

namespace DrivingCRM.Views.Private.CRM
{
    public partial class AddEvents : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                this.DDL_Agencies.SelectedIndexChanged += new EventHandler(DDL_Agencies_SelectedIndexChanged);
                this.UP_AgencyStakeholder.Update();
                this.DP_DateWithHour.SelectedDate = DateTime.Now;
            }
        }
        
        void DDL_Agencies_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDL_Stakeholder.DataBind();
        }

        protected void B_AddEvent_Click(object sender, EventArgs e)
        {
            string ret = EntityManager.AddEvent(this.DDL_Type.SelectedValue, this.DDL_Duration.SelectedIndex + 1, this.DP_DateWithHour.SelectedDate.Value, new Guid(this.DDL_Stakeholder.SelectedValue), int.Parse(this.DDL_Agencies.SelectedValue));
            if (ret == "No error")
                this.L_ErrorMessage.Text = "L'évènement a correctement été ajouté.";
            else
                this.L_ErrorMessage.Text = "Une erreur est survenue lors de l'ajout d'un évènement, veuillez saisir les champs requis.";
        }
    }
}